<template>
	<view class="container">
		<!-- 顶部标题栏 -->
		<!-- 主体内容区 -->
		<view class="content">
			<!-- 蓝牙连接设置区域 -->
			<view class="card bluetooth-card">
				<view class="card-header">
					<text class="card-title">蓝牙连接</text>
					<view class="connection-status" :class="getConnectionStatusClass()">
						<text>{{ bluetoothStateText }}</text>
					</view>
				</view>
				
				<view class="card-body">
					<!-- 模块类型选择 -->
					<view class="form-item">
						<text class="form-label">模块类型</text>
						<view class="form-control">
							<picker @change="onModuleTypeChange" :value="moduleTypeIndex" :range="moduleTypes">
								<view class="picker-value">{{ moduleTypes[moduleTypeIndex] }}</view>
							</picker>
						</view>
					</view>
					
					<!-- 自定义UUID设置 (仅在选择自定义UUID模式时显示) -->
					<view v-if="moduleTypeIndex === 2" class="uuid-settings">
						<view class="form-item">
							<text class="form-label">服务UUID</text>
							<input class="form-input" v-model="customUUID.serviceId" placeholder="请输入服务UUID" />
						</view>
						<view class="form-item">
							<text class="form-label">写特征UUID</text>
							<input class="form-input" v-model="customUUID.writeId" placeholder="请输入写特征UUID" />
						</view>
						<view class="form-item">
							<text class="form-label">通知特征UUID</text>
							<input class="form-input" v-model="customUUID.notifyId" placeholder="请输入通知特征UUID" />
						</view>
					</view>
					
					<!-- 连接保活设置 -->
					<view class="form-item">
						<text class="form-label">自动重连</text>
						<switch :checked="heartbeatOptions.autoReconnect" @change="onAutoReconnectChange" color="#3a86ff" style="transform:scale(0.7)"/>
					</view>
					
					<view v-if="heartbeatOptions.autoReconnect" class="form-item">
						<text class="form-label">最大重连次数</text>
						<input class="form-input" type="number" v-model="heartbeatOptions.maxReconnectAttempts" @change="updateHeartbeatOptions" />
					</view>
					
					<view class="form-item">
						<text class="form-label">心跳保活</text>
						<switch :checked="heartbeatOptions.enableHeartbeat" @change="onHeartbeatEnableChange" color="#3a86ff" style="transform:scale(0.7)"/>
					</view>
					
					<view v-if="heartbeatOptions.enableHeartbeat" class="form-item">
						<text class="form-label">心跳周期(秒)</text>
						<input class="form-input" type="number" v-model="heartbeatOptions.heartbeatPeriod" @change="updateHeartbeatOptions" />
					</view>
					
					<!-- 蓝牙操作按钮 -->
					<view class="button-group">
						<button class="btn" :disabled="bluetoothState === 1" @click="toggleScan">{{ isScanning ? '停止搜索' : '搜索设备' }}</button>
						<button class="btn" :disabled="bluetoothState !== 2" @click="disconnect">断开连接</button>
					</view>
					
					<!-- 蓝牙设备列表 -->
					<view class="device-list" v-if="isScanning || devicesList.length > 0">
						<view class="list-header">
							<text>设备列表</text>
							<text v-if="isScanning" class="scanning-indicator">搜索中...</text>
						</view>
						<scroll-view scroll-y class="scroll-list">
							<view v-if="devicesList.length === 0" class="empty-list">
								<text>未发现设备</text>
							</view>
							<view v-else>
								<view v-for="(device, index) in devicesList" :key="index" class="device-item" @click="connectDevice(device)">
									<view class="device-info">
										<text class="device-name">{{ device.name || device.localName || '未知设备' }}</text>
										<text class="device-id">{{ device.deviceId }}</text>
									</view>
									<text class="rssi">{{ device.RSSI }} dBm</text>
								</view>
							</view>
						</scroll-view>
					</view>
				</view>
			</view>
			
			<!-- Modbus通信区域 -->
			<view class="card modbus-card">
				<view class="card-header">
					<text class="card-title">Modbus通信</text>
				</view>
				
				<view class="card-body">
					<!-- Modbus参数设置 -->
					<view class="form-item">
						<text class="form-label">从站地址</text>
						<input class="form-input" type="number" v-model="modbusParams.slaveId" placeholder="1-247" />
					</view>
					
					<view class="form-item">
						<text class="form-label">功能码</text>
						<view class="form-control">
							<picker @change="onFunctionCodeChange" :value="functionCodeIndex" :range="functionCodes" range-key="name">
								<view class="picker-value">{{ functionCodes[functionCodeIndex].name }}</view>
							</picker>
						</view>
					</view>
					
					<view class="form-item">
						<text class="form-label">起始地址</text>
						<input class="form-input" type="number" v-model="modbusParams.startAddress" placeholder="0-65535" />
					</view>
					
					<view class="form-item" v-if="isReadFunction">
						<text class="form-label">读取数量</text>
						<input class="form-input" type="number" v-model="modbusParams.quantity" placeholder="1-125" />
					</view>
					
					<view class="form-item" v-if="isSingleWriteFunction">
						<text class="form-label">写入值</text>
						<input class="form-input" type="number" v-model="modbusParams.value" placeholder="0-65535" />
					</view>
					
					<view v-if="isMultipleWriteFunction">
						<view class="form-item">
							<text class="form-label">写入数量</text>
							<input class="form-input" type="number" v-model="modbusParams.writeCount" @change="updateWriteValues" placeholder="1-123" />
						</view>
						
						<view class="write-values-list">
							<view class="form-item" v-for="(value, index) in modbusParams.writeValues" :key="index">
								<text class="form-label">值 {{ index + 1 }}</text>
								<input class="form-input" type="number" v-model="modbusParams.writeValues[index]" placeholder="0-65535" />
							</view>
						</view>
					</view>
					
					<!-- Modbus操作按钮 -->
					<view class="button-group">
						<button class="btn btn-primary"  @click="sendModbusRequest">发送请求</button>
					</view>
					
					<!-- 通信日志 -->
					<view class="communication-log">
						<view class="log-header">
							<text>通信日志</text>
							<button class="btn-small" @click="clearLog">清空</button>
						</view>
						<scroll-view scroll-y class="log-content" :scroll-top="scrollTop">
							<view v-for="(log, index) in communicationLogs" :key="index" class="log-item" :class="log.type">
								<text class="log-time">{{ log.time }}</text>
								<text class="log-message">{{ log.message }}</text>
							</view>
						</scroll-view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
// #ifdef APP-PLUS
// import  BluetoothModbus from '@/utils/bluetoothModbus_plus.js'
// import { 
// 	BLUETOOTH_STATE, 
// 	MODBUS_FUNCTION_CODE, 
// 	BLUETOOTH_MODULE_TYPE
// } from '@/utils/bluetoothModbus_plus.js'
// #endif
import { 
	BLUETOOTH_STATE, 
	MODBUS_FUNCTION_CODE, 
	BLUETOOTH_MODULE_TYPE,
	BluetoothModbus
} from '@/utils/bluetoothModbus.js'

export default {
	data() {
		return {
				// 蓝牙相关
				bluetoothManager: null,
				bluetoothState: BLUETOOTH_STATE.DISCONNECTED,
				extraInfo: null, // 保存额外状态信息
				isScanning: false,
				devicesList: [],
				moduleTypeIndex: 0,
				moduleTypes: ['常规模组', 'BT16模组', '指定UUID', '低功耗蓝牙'],
				customUUID: {
					serviceId: '',
					writeId: '',
					notifyId: ''
				},
				// 心跳保活设置
				heartbeatOptions: {
					enableHeartbeat: true,       // 是否启用心跳
					heartbeatPeriod: 30,          // 心跳周期(秒)
					autoReconnect: true,         // 是否自动重连
					maxReconnectAttempts: 10     // 最大重连次数
				},
			
			// Modbus相关
			functionCodeIndex: 0,
			functionCodes: [
				{ code: MODBUS_FUNCTION_CODE.READ_HOLDING_REGISTERS, name: '读保持寄存器' },
				{ code: MODBUS_FUNCTION_CODE.READ_INPUT_REGISTERS, name: '读输入寄存器' },
				{ code: MODBUS_FUNCTION_CODE.WRITE_SINGLE_REGISTER, name: '写单个寄存器' },
				{ code: MODBUS_FUNCTION_CODE.WRITE_MULTIPLE_REGISTERS, name: '写多个寄存器' },
				{ code: MODBUS_FUNCTION_CODE.READ_COILS, name: '读线圈' },
				{ code: MODBUS_FUNCTION_CODE.READ_DISCRETE_INPUTS, name: '读离散输入' },
				{ code: MODBUS_FUNCTION_CODE.WRITE_SINGLE_COIL, name: '写单个线圈' },
				{ code: MODBUS_FUNCTION_CODE.WRITE_MULTIPLE_COILS, name: '写多个线圈' }
			],
			modbusParams: {
				slaveId: 1, // 从站地址
				startAddress: 0, // 起始地址
				quantity: 1, // 读取数量
				value: 0, // 写入值
				writeCount: 1, // 写入数量
				writeValues: [0]
			},
			// 通信日志
			communicationLogs: [],
			scrollTop: 0
		}
	},
	computed: {
		bluetoothStateText() {
			switch (this.bluetoothState) {
				case BLUETOOTH_STATE.CONNECTED:
					return '连接服务成功'
				case BLUETOOTH_STATE.SERVICES_DISCOVERING:
					if (this.extraInfo && this.extraInfo.serviceRetryCount !== undefined) {
						return `正在读取服务 (${this.extraInfo.serviceRetryCount}/${this.extraInfo.maxServiceRetryAttempts})`
					}
					return '正在读取服务'
				case BLUETOOTH_STATE.CONNECTING:
					return '连接中'
				case BLUETOOTH_STATE.RECONNECTING:
					return `正在重连 (${this.bluetoothManager.reconnectCount}/${this.bluetoothManager.maxReconnectAttempts})`
				case BLUETOOTH_STATE.DISCONNECTED:
				default:
					return '未连接'
			}
		},
		isReadFunction() {
			const code = this.functionCodes[this.functionCodeIndex].code
			return code === MODBUS_FUNCTION_CODE.READ_COILS || 
				   code === MODBUS_FUNCTION_CODE.READ_DISCRETE_INPUTS || 
				   code === MODBUS_FUNCTION_CODE.READ_HOLDING_REGISTERS || 
				   code === MODBUS_FUNCTION_CODE.READ_INPUT_REGISTERS
		},
		isSingleWriteFunction() {
			const code = this.functionCodes[this.functionCodeIndex].code
			return code === MODBUS_FUNCTION_CODE.WRITE_SINGLE_COIL || 
				   code === MODBUS_FUNCTION_CODE.WRITE_SINGLE_REGISTER
		},
		isMultipleWriteFunction() {
			const code = this.functionCodes[this.functionCodeIndex].code
			return code === MODBUS_FUNCTION_CODE.WRITE_MULTIPLE_COILS || 
				   code === MODBUS_FUNCTION_CODE.WRITE_MULTIPLE_REGISTERS
		},
		currentFunctionCode() {
			return this.functionCodes[this.functionCodeIndex].code
		}
	},
	onLoad() {
		// 初始化蓝牙管理器
		this.initBluetoothManager()
	},
	onUnload() {
		// 页面卸载时关闭蓝牙
		if (this.bluetoothManager) {
			this.bluetoothManager.close()
		}
	},
	methods: {
		// 初始化蓝牙管理器
		initBluetoothManager() {
			this.bluetoothManager = new BluetoothModbus()
			this.onModuleTypeChange({detail: {value: 1}})
			
			// 设置心跳保活参数
			this.updateHeartbeatOptions()
			
			// 设置状态变化回调
			this.bluetoothManager.onStateChange((state, extraInfo) => {
				this.bluetoothState = state
				// 保存额外信息，用于UI显示
				this.extraInfo = extraInfo
				
				if (state === BLUETOOTH_STATE.DISCONNECTED) {
					this.addLog('系统', '蓝牙已断开连接')
				} else if (state === BLUETOOTH_STATE.CONNECTING) {
					this.addLog('系统', '正在连接蓝牙设备')
				} else if (state === BLUETOOTH_STATE.RECONNECTING) {
					this.addLog('系统', `正在重连蓝牙设备 (${this.bluetoothManager.reconnectCount}/${this.bluetoothManager.maxReconnectAttempts})`)
				} else if (state === BLUETOOTH_STATE.SERVICES_DISCOVERING) {
					// 如果有额外信息，显示重试次数
					if (extraInfo && extraInfo.serviceRetryCount !== undefined) {
						this.addLog('系统', `正在读取服务，第${extraInfo.serviceRetryCount}次尝试（最多${extraInfo.maxServiceRetryAttempts}次）`)
					} else {
						this.addLog('系统', '蓝牙已连接，正在读取服务')
					}
				} else if (state === BLUETOOTH_STATE.CONNECTED) {
					this.addLog('系统', '蓝牙服务连接成功')
				}
			})
			
			// 设置设备发现回调
			this.bluetoothManager.onDeviceFound((devices) => {
				this.devicesList = [...devices]
			})
			
			// 设置数据接收回调
			this.bluetoothManager.onDataReceived((data) => {
				try {
					const result = this.bluetoothManager.parseModbusResponse(data)
					if (result.error) {
						this.addLog('错误', `解析响应失败: ${result.error}`)
						return
					}
					
					let logMessage = `从站: ${result.slaveId}, 功能码: ${result.functionCode}`
					console.log('result--------------', result);
					if (result.values) {
						logMessage += `, 数据: ${JSON.stringify(result.values)}`
					} else if (result.value !== undefined) {
						logMessage += `, 值: ${result.value}`
					} else if (result.address !== undefined) {
						logMessage += `, 地址: ${result.address}`
						if (result.quantity !== undefined) {
							logMessage += `, 数量: ${result.quantity}`
						}
					}
					
					this.addLog('接收', logMessage)
				} catch (error) {
					this.addLog('错误', `解析响应异常: ${error.message}`)
				}
			})
			
			// 设置错误回调
			this.bluetoothManager.onError((error) => {
				this.addLog('错误', error.message)
			})
			
			// 初始化蓝牙模块
			this.bluetoothManager.init().catch(error => {
				console.error('初始化蓝牙失败', error)
			})
		},
		
		// 模块类型变更
		onModuleTypeChange(e) {
			this.moduleTypeIndex = e.detail.value
			
			// 根据选择的模块类型设置UUID
			let moduleType
			switch (parseInt(this.moduleTypeIndex)) {
				case 0:
					moduleType = BLUETOOTH_MODULE_TYPE.NORMAL
					break
				case 1:
					moduleType = BLUETOOTH_MODULE_TYPE.BT16
					break
				case 2:
					moduleType = BLUETOOTH_MODULE_TYPE.CUSTOM
					break
				case 3:
					moduleType = BLUETOOTH_MODULE_TYPE.BLE
					this.addLog('系统', '已切换到低功耗蓝牙(BLE)模式')
					break
				default:
					moduleType = BLUETOOTH_MODULE_TYPE.NORMAL
			}
			
			this.bluetoothManager.setModuleType(moduleType, this.customUUID)
		},
		
		// 功能码变更
		onFunctionCodeChange(e) {
			this.functionCodeIndex = e.detail.value
			
			// 根据功能码类型重置相关参数
			if (this.isReadFunction) {
				this.modbusParams.quantity = 1
			} else if (this.isSingleWriteFunction) {
				this.modbusParams.value = 0
			} else if (this.isMultipleWriteFunction) {
				this.modbusParams.writeCount = 1
				this.modbusParams.writeValues = [0]
			}
		},
		
		// 更新写入值数组
		updateWriteValues() {
			const count = parseInt(this.modbusParams.writeCount) || 1
			const values = [...this.modbusParams.writeValues]
			
			// 调整数组大小
			if (count > values.length) {
				// 添加新元素
				for (let i = values.length; i < count; i++) {
					values.push(0)
				}
			} else if (count < values.length) {
				// 移除多余元素
				values.splice(count)
			}
			
			this.modbusParams.writeValues = values
		},
		
		// 切换扫描状态
		toggleScan() {
			if (this.isScanning) {
				this.stopScan()
			} else {
				this.startScan()
			}
		},
		
		// 开始扫描
		startScan() {
			this.isScanning = true
			this.devicesList = []
			this.addLog('系统', '开始搜索蓝牙设备')
			
			this.bluetoothManager.startScan().catch(error => {
				this.isScanning = false
				this.addLog('错误', `搜索蓝牙设备失败: ${error.message || '未知错误'}`)
			})
		},
		
		// 停止扫描
		stopScan() {
			this.isScanning = false
			console.log('停止扫描------------------------')
			this.bluetoothManager.stopScan()
			this.addLog('系统', '停止搜索蓝牙设备')
		},
		
		// 连接设备
		connectDevice(device) {
			if (this.bluetoothState !== BLUETOOTH_STATE.DISCONNECTED) {
				return
			}
			
			this.addLog('系统', `正在连接设备: ${device.name || device.localName || '未知设备'}`)
			
			this.bluetoothManager.connect(device.deviceId)
				.then(() => {
					this.deviceName = device.name || device.localName || '未知设备';
					uni.setStorageSync('cur_device', device);
					this.stopScan()
				})
				.catch(error => {
					this.addLog('错误', `连接设备失败: ${error.message || '未知错误'}`)
				})
		},
		
		// 断开连接
		disconnect() {
			if (this.bluetoothState === BLUETOOTH_STATE.DISCONNECTED) {
				return
			}
			
			this.bluetoothManager.disconnect()
			this.addLog('系统', '断开蓝牙连接')
		},
		
		// 更新心跳保活设置
		updateHeartbeatOptions() {
			if (!this.bluetoothManager) return
			
			// 心跳周期从秒转为毫秒
			const heartbeatPeriodMs = this.heartbeatOptions.heartbeatPeriod * 1000
			
			// 设置心跳保活参数
			this.bluetoothManager.setHeartbeatOptions(
				new Uint8Array([0x00]), // 心跳数据包
				this.heartbeatOptions.enableHeartbeat ? heartbeatPeriodMs : 0, // 心跳周期，0表示禁用
				this.heartbeatOptions.autoReconnect,                          // 是否自动重连
				this.heartbeatOptions.maxReconnectAttempts,                  // 最大重连次数
				3000                                                        // 重连延迟3秒
			)
			
			this.addLog('系统', `已${this.heartbeatOptions.enableHeartbeat ? '启用' : '禁用'}心跳保活，${this.heartbeatOptions.autoReconnect ? '启用' : '禁用'}自动重连`)
		},
		
		// 自动重连开关变更
		onAutoReconnectChange(e) {
			this.heartbeatOptions.autoReconnect = e.detail.value
			this.updateHeartbeatOptions()
		},
		
		// 心跳保活开关变更
		onHeartbeatEnableChange(e) {
			this.heartbeatOptions.enableHeartbeat = e.detail.value
			this.updateHeartbeatOptions()
		},
		
		// 发送Modbus请求
		sendModbusRequest() {
			if (this.bluetoothState !== BLUETOOTH_STATE.CONNECTED) {
				this.addLog('错误', '蓝牙未连接')
				return
			}
			
			const slaveId = parseInt(this.modbusParams.slaveId) || 1
			const functionCode = this.currentFunctionCode
			const startAddress = parseInt(this.modbusParams.startAddress) || 0
			let value;
			
			// 根据功能码类型准备参数
			if (this.isReadFunction) {
				value = parseInt(this.modbusParams.quantity) || 1
			} else if (this.isSingleWriteFunction) {
				value = parseInt(this.modbusParams.value) || 0
			} else if (this.isMultipleWriteFunction) {
				value = this.modbusParams.writeValues.map(v => parseInt(v) || 0)
			}
			
			// 记录请求日志
			let logMessage = `从站: ${slaveId}, 功能码: ${functionCode}, 地址: ${startAddress}`
			if (this.isReadFunction) {
				logMessage += `, 数量: ${value}`
			} else if (this.isSingleWriteFunction) {
				logMessage += `, 值: ${value}`
			} else if (this.isMultipleWriteFunction) {
				logMessage += `, 数量: ${value.length}, 值: ${JSON.stringify(value)}`
			}
			this.addLog('发送', logMessage)
			
			// 发送请求
			this.bluetoothManager.sendModbusRequest(slaveId, functionCode, startAddress, value)
				.catch(error => {
					this.addLog('错误', `发送请求失败: ${error.message || '未知错误'}`)
				})
		},
		
		// 添加日志
		addLog(type, message) {
			const now = new Date()
			const time = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}.${now.getMilliseconds().toString().padStart(3, '0')}`
			
			this.communicationLogs.push({
				type: type.toLowerCase(),
				time,
				message
			})
			
			// 限制日志数量
			if (this.communicationLogs.length > 100) {
				this.communicationLogs.shift()
			}
			
			// 滚动到底部
			this.$nextTick(() => {
				this.scrollTop = 9999999
			})
		},
		
		// 清空日志
		clearLog() {
			this.communicationLogs = []
		},
		
		// 获取连接状态样式类
		getConnectionStatusClass() {
			switch (this.bluetoothState) {
				case BLUETOOTH_STATE.CONNECTED:
					return 'connected'
				case BLUETOOTH_STATE.CONNECTING:
					return 'connecting'
				case BLUETOOTH_STATE.RECONNECTING:
					return 'reconnecting'
				case BLUETOOTH_STATE.SERVICES_DISCOVERING:
					return 'discovering'
				case BLUETOOTH_STATE.DISCONNECTED:
				default:
					return 'disconnected'
			}
		}
	}
}
</script>

<style>
/* 全局样式 */
.container {
	display: flex;
	flex-direction: column;
	height: 100vh;
	background-color: #f5f7fa;
}

/* 头部样式 */
.header {
	background-color: #3a86ff;
	padding: 20rpx 30rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.title {
	color: #ffffff;
	font-size: 36rpx;
	font-weight: bold;
}

/* 内容区样式 */
.content {
	flex: 1;
	padding: 20rpx;
	overflow-y: auto;
}

/* 卡片样式 */
.card {
	background-color: #ffffff;
	border-radius: 16rpx;
	box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.1);
	margin-bottom: 20rpx;
	overflow: hidden;
}

.card-header {
	padding: 20rpx 30rpx;
	border-bottom: 1rpx solid #eaeaea;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.card-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333333;
}

.card-body {
	padding: 30rpx;
}

/* 表单样式 */
.form-item {
	margin-bottom: 20rpx;
	display: flex;
	align-items: center;
}

.form-label {
	width: 180rpx;
	font-size: 28rpx;
	color: #666666;
}

.form-control {
	flex: 1;
}

.form-input {
	flex: 1;
	height: 70rpx;
	border: 1rpx solid #dcdfe6;
	border-radius: 8rpx;
	padding: 0 20rpx;
	font-size: 28rpx;
	background-color: #f8f9fa;
}

.picker-value {
	height: 70rpx;
	line-height: 70rpx;
	border: 1rpx solid #dcdfe6;
	border-radius: 8rpx;
	padding: 0 20rpx;
	font-size: 28rpx;
	background-color: #f8f9fa;
}

/* UUID设置样式 */
.uuid-settings {
	background-color: #f8f9fa;
	padding: 20rpx;
	border-radius: 8rpx;
	margin-bottom: 20rpx;
}

/* 按钮样式 */
.button-group {
	display: flex;
	justify-content: space-between;
	margin: 30rpx 0;
}

.btn {
	flex: 1;
	margin: 0 10rpx;
	height: 80rpx;
	line-height: 80rpx;
	text-align: center;
	border-radius: 8rpx;
	font-size: 28rpx;
	background-color: #f0f2f5;
	color: #333333;
}

.btn:first-child {
	margin-left: 0;
}

.btn:last-child {
	margin-right: 0;
}

.btn-primary {
	background-color: #3a86ff;
	color: #ffffff;
}

.btn-small {
	padding: 6rpx 20rpx;
	font-size: 24rpx;
	background-color: #f0f2f5;
	color: #666666;
	border-radius: 6rpx;
}

/* 连接状态样式 */
.connection-status {
	padding: 6rpx 20rpx;
	border-radius: 30rpx;
	font-size: 24rpx;
}

.disconnected {
	background-color: #f56c6c;
	color: #ffffff;
}

.connecting {
	background-color: #e6a23c;
	color: #ffffff;
}

.discovering {
	background-color: #409eff;
	color: #ffffff;
}

.reconnecting {
	background-color: #9c27b0;
	color: #ffffff;
	animation: blink 1s infinite;
}

@keyframes blink {
	0% { opacity: 1; }
	50% { opacity: 0.5; }
	100% { opacity: 1; }
}

.connected {
	background-color: #67c23a;
	color: #ffffff;
}

/* 设备列表样式 */
.device-list {
	margin-top: 20rpx;
	border: 1rpx solid #eaeaea;
	border-radius: 8rpx;
}

.list-header {
	padding: 16rpx 20rpx;
	background-color: #f8f9fa;
	border-bottom: 1rpx solid #eaeaea;
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 28rpx;
	color: #666666;
}

.scanning-indicator {
	color: #3a86ff;
	font-size: 24rpx;
}

.scroll-list {
	max-height: 400rpx;
}

.empty-list {
	padding: 40rpx 0;
	text-align: center;
	color: #999999;
	font-size: 28rpx;
}

.device-item {
	padding: 20rpx;
	border-bottom: 1rpx solid #eaeaea;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.device-item:active {
	background-color: #f0f2f5;
}

.device-info {
	display: flex;
	flex-direction: column;
}

.device-name {
	font-size: 28rpx;
	color: #333333;
	margin-bottom: 6rpx;
}

.device-id {
	font-size: 24rpx;
	color: #999999;
}

.rssi {
	font-size: 24rpx;
	color: #666666;
}

/* 写入值列表样式 */
.write-values-list {
	max-height: 400rpx;
	overflow-y: auto;
	border: 1rpx solid #eaeaea;
	border-radius: 8rpx;
	padding: 20rpx;
	margin-bottom: 20rpx;
}

/* 通信日志样式 */
.communication-log {
	margin-top: 30rpx;
}

.log-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 10rpx;
}

.log-content {
	height: 300rpx;
	border: 1rpx solid #eaeaea;
	border-radius: 8rpx;
	padding: 10rpx;
	background-color: #f8f9fa;
}

.log-item {
	font-size: 24rpx;
	padding: 6rpx 0;
	display: flex;
}

.log-time {
	color: #999999;
	margin-right: 10rpx;
	white-space: nowrap;
}

.log-message {
	flex: 1;
	word-break: break-all;
}

.log-item.system .log-message {
	color: #909399;
}

</style>
